package net.xo68.destiny.manager.converter;

import net.xo68.destiny.contract.domain.node.NodeRegistry;
import net.xo68.destiny.contract.enums.NodeTypeEnum;
import net.xo68.destiny.core.common.ObjectConverter;
import net.xo68.destiny.manager.entity.NodeHeartbeat;
import org.springframework.stereotype.Component;

@Component
public class NodeHeartbeat2NodeRegistryConverter implements ObjectConverter<NodeHeartbeat, NodeRegistry> {

    @Override
    public NodeRegistry convert(NodeHeartbeat nodeHeartbeat) {
        NodeRegistry nodeRegistry=new NodeRegistry();
        nodeRegistry.setNodeHost(nodeHeartbeat.getNodeHost());
        nodeRegistry.setWorkGroup(nodeHeartbeat.getWorkGroupName());
        nodeRegistry.setNodeType(NodeTypeEnum.valueOf(nodeHeartbeat.getNodeTypeName()));
        nodeRegistry.setCpuUsage(nodeHeartbeat.getCpuUsage());
        nodeRegistry.setMemoryUsage(nodeHeartbeat.getMemoryUsage());
        nodeRegistry.setLoadAverage(nodeHeartbeat.getLoadAverage());
        nodeRegistry.setLastTime(nodeHeartbeat.getLastTime());
        return nodeRegistry;
    }
}
